import {
	config
} from '../../config/index';

/** 获取商品列表 */
function mockFetchGoodsList(pageIndex = 1, pageSize = 20) {
	const {
		delay
	} = require('../_utils/delay');
	const {
		getGoodsList
	} = require('../../model/goods');
	const {
		$api
	} = require('../../utils/request').Api;
	return delay().then(() =>
		$api.goodsList({
			pageIndex,
			pageSize
		}).then((item) => {
			console.log(item);
			return {
				spuId: item.spuId,
				thumb: item.primaryImage,
				title: item.title,
				price: item.minSalePrice,
				originPrice: item.maxLinePrice,
				tags: item.spuTagList.map((tag) => tag.title),
			};
		})
		// getGoodsList(pageIndex, pageSize).map((item) => {
		// 	// console.log(pageIndex, pageSize);
		// 	return {
		// 		spuId: item.spuId,
		// 		thumb: item.primaryImage,
		// 		title: item.title,
		// 		price: item.minSalePrice,
		// 		originPrice: item.maxLinePrice,
		// 		tags: item.spuTagList.map((tag) => tag.title),
		// 	};
		// }),
	);
}

/** 获取商品列表 */
export function fetchGoodsList(pageIndex = 1, pageSize = 20) {
	if (config.useMock) {
		return mockFetchGoodsList(pageIndex, pageSize);
	}
	return new Promise((resolve) => {
		resolve('real api');
	});
}